<?php 

class NAV {
	var $body;
	var $entry;
	var $show = true;
	
	
	function NAV(){
		//require_once("nav.inc.php");
		$this->body="";
		$this->entry=array();/*
			"Home"=>array(
				"home"=>10,
				"Abmelden"=>11),
			"Administration"=>array(
				"administration"=>10,
				"Plugins"=>900,
				"Pluginsd"=>900,
				"Pluginss"=>900,
				"Pluginsa"=>900,
				"Pluginsf"=>900,
				"Pluginsh"=>900,
				"Pluginsj"=>900),
			"Google"=>"http://www.google.com"
		);*/
		
		$this->loadNav();
		
	}
	
	function loadNav(){		
		$file=file(getcwd()."/config/nav.inc.php");
				
		foreach($file as $line){
		
			if(strlen($line)>4){
				if(substr($line,0,2)=="%%" && strlen($last[0])>0){
					if($last[2]==0){
						$last[2]=1;
						$this->entry[$last[0]]=array();
						$this->entry[$last[0]][$last[0]]=preg_replace("/\r|\n/s", "",$last[1]);
					
					}
					$tmp=explode("%%", $line);
					
					if(strlen($tmp[2])<=7)
						$tmp[2]=(int) $tmp[2];
						
					$this->entry[$last[0]][$tmp[1]]=preg_replace("/\r|\n/s", "",$tmp[2]);
					
				}else{
					$last=explode("%%",$line);
					if(strlen($last[1])<=7)
						$last[1]=(int) $last[1];
						
					$this->entry[$last[0]]=$last[1];
					
					$last[2]=0;
					
					
				}
			}
		}		
	}
	/*
	function javascriptArray($title){
		$output="$title=new Array(";
		$start0=true;
		foreach($this->entry as $name=>$value){
			if(is_array($value)){
				if(!$start0)
					$output.=",";
				else
					$start0=false;
					
				$output.="new Array(\n\t'$name', \n\t'".preg_replace("/\r|\n/s", "",  array_shift($value))."', \n\tnew Array(";
				$start1=true;
				foreach($value as $name=>$value){
					if(!$start1)
						$output.=",";
					else
						$start1=false;

					
					$output.="\n\t\tnew Array('$name', '".preg_replace("/\r|\n/s", "",  $value)."')";
				}
				
				$output.="\n\t\t)\n\t)";

			}else{
				if(!$start0)
					$output.=",\n";
				else
					$start0=false;
					
				$output.="new Array('$name', '".preg_replace("/\r|\n/s", "",  $value)."')";
			}
		};
		$output.="\n);";
		echo $output;
		//return $output;	
	}
	*/
	function generateNav($user_group, $user_id){
		global $plugin;
	
		$this->body.="<br />\n<table width=\"100%\">";
		$id=0;
		foreach($this->entry as $name=>$value){
			if(is_array($value)){
				$tmp0="<tr id=\"nav_".$id."\" ><td class=\"c\" height=\"30px\">";
				
				if(isset($_COOKIE['nav_'.$id.'_content']) && $_COOKIE['nav_'.$id.'_content'] == "false")
					$tmp0.="<img id=\"nav_".$id."_link\" onclick=\"navigation('nav_".$id."')\" src=\"images/icon_big.png\" style=\"position:relative;left:100%;margin-left:-20px;margin-right:3px;\">";
				else
					$tmp0.="<img id=\"nav_".$id."_link\" onclick=\"navigation('nav_".$id."')\" src=\"images/icon_small.png\" style=\"position:relative;left:100%;margin-left:-20px;margin-right:3px;\">";
				
				
				$tmp0.="<a href=\"".$this->hyperlink(array_shift($value))."\"><span style=\"font-size:130%;\">".$name."</span></a>
				</td></tr>				
				<tr id=\"nav_".$id."_content\"";
				
				if(isset($_COOKIE['nav_'.$id.'_content']) && $_COOKIE['nav_'.$id.'_content'] == "false")
					$tmp0.=" style=\"display:none\"";
					
				$tmp0.="><td><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
				
				$tmp="";	
				
				foreach($value as $name2=>$value2){
					//echo "<pre>";
					//print_r( $value2);
					//echo "</pre>";
					if(is_numeric($value2) && is_file($plugin[$value2][1].".settings.php")){
						require($plugin[$value2][1].".settings.php");
						if($user_group==1000 or in_array($user_group, $plugin["access_view_group"]) or in_array($user_id, $plugin["access_view_users"])){
							$tmp.="<tr><td class=\"l\" style=\"padding-left:20px;\">
							<a href=\"".$this->hyperlink($value2)."\">".$name2."</a>
							</td></tr>";
							
						};
					}else{	
						$tmp.="<tr><td class=\"l\" style=\"padding-left:20px;\">
						<a href=\"".$value2."\">".$name2."</a>
						</td></tr>";
					}
				}
				
				if($tmp!=""){
					$this->body.=$tmp0.$tmp;
					$this->body.="</table></td></tr>";
				}
				
				
				
				$id++;
			}else{
				if(is_numeric($value) && is_file($plugin[$value][1].".settings.php")){
					require($plugin[$value][1].".settings.php");
					if($user_group==1000 or in_array($user_group, $plugin["access_view_group"]) or in_array($user_id, $plugin["access_view_users"])){
						$this->body.="<tr><td class=\"l\" style=\"padding-left:20px;\">
						<a href=\"".$this->hyperlink($value)."\">".$name."</a>
						</td></tr>";
					};
				}else{	
					$this->body.="<tr><td class=\"l\" style=\"padding-left:20px;\">
					<a href=\"".$this->hyperlink($value)."\">".$name."</a>
					</td></tr>";
				}
			}
		};
		
		$this->body.='</table>';
		return $this->body;
		
		
	}
	
	function hyperlink($value){
		if(is_numeric($value))
			return "index.php?com=".$value;
		else
			return $value;	
	}
	
	
}

?>